$(function(){
    init("0");
})

var pageNum = 0;
var previousStatus = "" ;
function init(approveStatus,refresh){
    if(refresh){
        pageNum = 0;
        $("#orders").html("");
    }
    if(previousStatus != approveStatus){
        previousStatus = approveStatus;
        pageNum = 0;
        $("#orders").html("");
    }
    $("#more").remove();
    $.ajax({
        url:server_url + '/rest/staff/orders.do',
        data:{staffId:userid,approveStatus:approveStatus,pageNum:pageNum,ran:Math.random()},
        success:function(data){
            console.log(data);
            if(data.data == null || data.data.length == 0){
                var more = '<div class="display_block" id="more">\
                <div class="gray"></div>\
                <p style="text-align: center">没有更多了</p></div>';
                $("#orders").append(more);
                return;
            }
            mapIfExist(function(order){
                var html = '<div class="display_block">\
                <div class="gray"></div>\
            <div class="pos_det">\
            <p class="order_num">订单号：'+order.orderCode+' <span>'+approveStatusName(order.approveStatus)+'</span></p>\
            <div class="det_con">\
            <img src="'+order.lstOrderDetail[0].productPic+'" alt="" class="">\
            <div class="">\
            <div class="con_tit">\
            <p>'+order.lstOrderDetail[0].productName+'</p>\
            <span>¥'+order.lstOrderDetail[0].productPrice+'/头</span>\
            </div>\
            <p class="con_normal">编号：'+order.lstOrderDetail[0].supplyProductID+' <span><i>X</i>'+order.lstOrderDetail[0].productNum+'</span></p>\
            <p class="con_normal">类型：'+order.lstOrderDetail[0].spec+'</p>\
            <p class="con_normal">交易日期：'+order.addTime.substring(0,10)+'</p>\
            </div>\
            <div class="ps_det">合计：¥'+order.price+'</div>\
            </div>\
            </div>\
            <div class="total_box">';
            if(order.approveStatus == '0'){
                html += '<div onclick="toDetail('+order.id+')">处理订单</div>'
            }
            html += '<span onclick="window.location.href=\'tel:'+order.lstOrderDetail[0].supplyMobile+'\'">联系卖家</span>\
            <p onclick="window.location.href=\'tel:'+order.consMobile+'\'">联系买家</p>\
            </div>\
            </div>';
                $("#orders").append(html);
            },data.data)
            var more = '<div class="display_block" id="more" onclick="init(\''+approveStatus+'\')">\
                <div class="gray"></div>\
                <p style="text-align: center">加载更多</p></div>';
            $("#orders").append(more);
            pageNum++
        }
    })
}
function toDetail(id){
    window.location.href='/LianniuWeb/staff/orderDetail.do?orderId='+id;
}
function approveStatusName(s){
    if(s == '0'){
        return "待处理"
    }
    if(s == '1')
    {
        return "审核中";
    }
    if(s == '2'){
        return "未通过"
    }
    if (s == '3'){
        return "已完成"
    }
    return "待处理"
}